package source.calcCmd;

public class Vec {
	public double x;
	public double y;
	
	public Vec add(double deltaX, double deltaY){
		x+=deltaX;
		y+=deltaY;
		return this;
	}
	
	public Vec addNR(double deltaX, double deltaY){
		return new Vec(x+deltaX,y+deltaY);
	}
	
	public Vec multiply(double r){
		x*=r;
		y*=r;
		return this;
	}
	
	// get a multiplied vector WITHOUT updating the vector
	public Vec multiplyNR(double d){
		return new Vec(x*d,y*d);
	}
	
	public static double distBetween(Vec a, Vec b){
		double val;
		
		val = (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);
		return Math.sqrt(val);
	}
	
	public static double angleBetween(Vec a,Vec b){
		double angle = 0;
		
		Vec X = a.getNormalized();
		Vec Y = b.getNormalized();
		// Get the dot product which gives the angle between 0 and PI, 
		// and get the sign from the sign of the Z coordinate of the cross product
		angle = (double) (Math.acos(X.x*Y.x+X.y*Y.y)*Math.signum(X.x*Y.y-X.y*Y.x));
		//angle = (float) (Math.acos(X.x*Y.x+X.y*Y.y)*Math.signum(X.y*Y.x-X.x*Y.y));
		return angle;
	}
	
	public Vec getNormalized(){
		double l = this.length();
		return new Vec(x/l,y/l);
	}
	
	public double length(){
		return Math.sqrt(x*x+y*y);
	}
	
	public Vec add(Vec v){
		x+=v.getX();
		y+=v.getY();
		return this;
	}
	
	public Vec addNR(Vec v) {
		return new Vec(x+v.getX(),y+v.getY());
	}
	
	public double getX() {
		return x;
	}
	public void setX(double x) {
		this.x = x;
	}
	public double getY() {
		return y;
	}
	public void setY(double y) {
		this.y = y;
	}
	
	public static Vec subTract(Vec a, Vec b){
		return new Vec(a.x-b.x,a.y-b.y);
	}
	
	public Vec(double x, double y){
		this.x = x;
		this.y = y;
	}
	
	public Vec(Vec v){
		x = v.getX();
		y = v.getY();
	}


	
}
